var Observer = require('Observer');


cc.Class({
    extends: Observer,

    properties: {
        chargeLayer: {default: null, displayName: "充值", type: cc.Prefab},
        itemPrefab: {default: null, displayName: "item", type: cc.Prefab},
        addNode: {default: null, displayName: "添加节点", type: cc.Node},
        contentNode: {default: null, displayName: "itemContent", type: cc.Node},

        ensurePrefab: {default: null, displayName: "购买确认对话框", type: cc.Prefab},

    },
    _getMsgList(){
        return [
            GameLocalMsg.Center.OnClickBuy,
        ]
    },
    _onMsg(msg, data){
        if (msg == GameLocalMsg.Center.OnClickBuy) {
            var layer = cc.instantiate(this.ensurePrefab);
            this.addNode.addChild(layer);
        }
    },
    onLoad: function () {
        this._initMsg();

        this.contentNode.destroyAllChildren();
        var cfg = [
            {gold: 500, money: 5},
            {gold: 1000, money: 10},
            {gold: 5000, money: 50},
            {gold: 10000, money: 100},

        ];
        for (var i = 0; i < cfg.length; i++) {
            var item = cfg[i];
            var clone = cc.instantiate(this.itemPrefab);
            this.contentNode.addChild(clone);

            var script = clone.getComponent("ShopItem");
            if (script) {
                script.setData(item);
            }
        }

    },
    onClickClose(){
        this.node.destroy();
    },
    onClickCharge(){
        var layer = cc.instantiate(this.chargeLayer);
        this.addNode.addChild(layer);
    },

});
